package leecode

import (
	"fmt"
	"sort"
	"strconv"
)

func largestNumber(nums []int) string {
	//将整数数组按字符串形式排序
	sort.Slice(nums, func(i, j int) bool {
		x := fmt.Sprintf("%d%d", nums[i], nums[j])
		y := fmt.Sprintf("%d%d", nums[j], nums[i])
		return x > y
	})
	var result string
	for i := 0; i < len(nums); i++ {
		result += strconv.Itoa(nums[i])
	}
	if result[0] == '0' {
		return "0"
	}
	return result
}
